@include('Index.header')
<style>
    .cl li {
        margin-bottom:10px;
    }
</style>
<body class="bg">
<form class="layui-form" action="{{ URL::action('Index\IndexController@postComment')}}">
    <!-- header start -->
    <div class="nav-wrapper">
        <div class="nav">
            <span class="y"><button  lay-submit lay-filter="formDemo" class="fa fa-send fa-send-grey" disable="true"></button></span>
            <a href="{{ URL::action('Index\IndexController@index')}}" class="z"><i class="fa fa-angle-left"></i></a>
            <span class="name">发帖</span>
        </div>
    </div>
    <div class="wp">
        <div class="post_from">
            <ul class="cl">
                <li>
                    <input type="text" class="layui-input"  style="font-size: 16px;"  autocomplete="off" value="" name="name" placeholder="标题"  >
                </li>
                <li class="bl_none area">
                    <textarea  class="layui-textarea"  placeholder="请输入内容" name="content" ></textarea>
                </li>
                <li style="padding:0px;">
                    <a href="javascript:;" class="y">
                        <i class="fa fa-camera"></i>
                        <input type="file" name="Filedata" id="filedata" style="width:30px;height:30px;opacity:0;position: absolute; top: 0; right: 0;">
                    </a>
                </li>
            </ul>
            <ul id="imglist" class="post_imglist cl">
            </ul>
        </div>
    </div>
    <!-- main postbox start -->
</form>
<script src="/js/ajaxfileupload.js?oSL" type="text/javascript"></script>
<script src="/js/buildfileupload.js?oSL" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){
        layui.use(['element', 'form'], function () {
            var element = layui.element;
            var form    = layui.form;
            //监听提交
            form.on('submit(formDemo)', function (data) {
                $('button[lay-filter=formDemo]').addClass("layui-btn-disabled");
                $('button[lay-filter=formDemo]').prop("disabled", true);//防连续点击提交
                var action = data.form.action;//表单提交URL地址
                $.post(action, data.field, function (obj) {
                    //根据返回结果作出相应处理
                    if (obj.code == 200) {
                        layer.msg(obj.msg, {anim: 1, time: 2000}, function () {
                            window.location.href="{{URL::action('Index\IndexController@index')}}";
                        })
                    }
                    else
                    {
                        layer.msg(obj.msg, {anim: 1});
                        $('button[lay-filter=formDemo]').removeClass("layui-btn-disabled");
                        $('button[lay-filter=formDemo]').prop("disabled", false);//可继续提交
                    }
                });
                return true;//注释掉这行代码后，表单将会以普通方式提交表单，否则以ajax方式提交表单
            });
        });
    })

    var imgexts = typeof imgexts == 'undefined' ? 'jpg, jpeg, gif, png' : imgexts;
    var STATUSMSG = {
        '-1' : '内部服务器错误',
        '0' : '上传成功',
        '1' : '不支持此类扩展名',
        '2' : '服务器限制无法上传那么大的附件',
        '3' : '用户组限制无法上传那么大的附件',
        '4' : '不支持此类扩展名',
        '5' : '文件类型限制无法上传那么大的附件',
        '6' : '今日您已无法上传更多的附件',
        '7' : '请选择图片文件(' + imgexts + ')',
        '8' : '附件文件无法保存',
        '9' : '没有合法的文件被上传',
        '10' : '非法操作',
        '11' : '今日您已无法上传那么大的附件'
    };
    var form = $('#postform');
    $(document).on('change', '#filedata', function() {
        popup.open('<img src="' + IMGDIR + '/imageloading.gif">');

        uploadsuccess = function(data) {


            var obj = eval('(' + data + ')');
            if(obj.code == '500') {
                popup.open('上传失败，请稍后再试', 'alert');
            }else{
                popup.close();
                $('#imglist').append('<li><span aid="'+obj.data.id+'" class="del"><a href="javascript:;"><img src="/static/image/mobile/images/icon_del.png" width="21" height="21"></a></span><span class="p_img"><a href="javascript:;"><img style="height:54px;width:54px;" id="aimg_'+obj.data.id+'" title="'+obj.data.id+'" src="'+obj.data.url+'" /></a></span><input type="hidden" name="image[]" value="'+obj.data.id+'" /></li>');
            }
        };

        if(typeof FileReader != 'undefined' && this.files[0]) {//note 支持html5上传新特性

            $.buildfileupload({
                uploadurl:'{{ URL::action('Index\IndexController@postUpload')}}',
                files:this.files,
                uploadformdata:{},
                uploadinputname:'Filedata',
                maxfilesize:"1024",
                success:uploadsuccess,
                error:function() {
                    popup.open('上传失败，请稍后再试', 'alert');
                }
            });

        } else {

            $.ajaxfileupload({
                uploadurl:'{{ URL::action('Index\IndexController@postUpload')}}',
                data:{uid:"60165", hash:"7ea455501d6378832eda49b2d1e3fb1c"},
                dataType:'text',
                fileElementId:'filedata',
                success:uploadsuccess,
                error: function() {
                    popup.open('上传失败，请稍后再试', 'alert');
                }
            });

        }
    });

    $('#postsubmit').on('click', function() {
        var obj = $(this);
        if(obj.attr('disable') == 'true') {
            return false;
        }

        obj.attr('disable', 'true').removeClass('btn_pn_blue').addClass('btn_pn_grey');
        popup.open('<img src="' + IMGDIR + '/imageloading.gif">');

        var postlocation = '';
        if(geo.errmsg === '' && geo.loc) {
            postlocation = geo.longitude + '|' + geo.latitude + '|' + geo.loc;
        }

        $.ajax({
            type:'POST',
            url:form.attr('action') + '&geoloc=' + postlocation + '&handlekey='+form.attr('id')+'&inajax=1',
            data:form.serialize(),
            dataType:'xml'
        })
            .success(function(s) {
                popup.open(s.lastChild.firstChild.nodeValue);
            })
            .error(function() {
                popup.open('网络出现问题，请稍后再试', 'alert');
            });
        return false;
    });

    $(document).on('click', '.del', function() {
        $(this).parent().remove();
    });

</script>



@include('Index.footer')